const {Sequelize,Op } = require('sequelize')

const fs = require('fs')
const path = require('path')



const sequelize = new Sequelize('soft2','postgres','112',{
    host:'zhaozhaozhao.store',
    dialect:'postgres'
})


    let obj ={}

    obj.Op=Op

    let files = fs.readdirSync(path.join(__dirname))

    tableFile = files.filter((item)=>{
      
      return item!=='sequelize.js' && item.endsWith('.js')

    })

    tableFile.forEach(item => {
      let fileName = item.replace('.js','')

      let name = fileName.toLowerCase()

      let table = require(path.join(__dirname,item))


      obj[fileName] = sequelize.define(name,table)
      
    });
    

    //sequelize.sync({force:true})



  obj.sequelizeSync =()=>{

    sequelize.sync({force:true}).then(res=>{

      obj.Student.bulkCreate(
        [
          {
            title:'论EF core的自我修养',
            thing1:'论EF core的自我修养',
            thing2:'论EF core的自我修养',
            thing3:'.Net',
            author:'InCerry',
            time:'2022-04-06 08:47'
            
          },
          {
            title:'论EF core的自我修养',
            thing1:'论EF core的自我修养',
            thing2:'论EF core的自我修养',
            thing3:'.Net',
            author:'InCerry',
            time:'2022-04-06 08:47'
            
          },
          {
            title:'论EF core的自我修养',
            thing1:'论EF core的自我修养',
            thing2:'论EF core的自我修养',
            thing3:'.Net',
            author:'InCerry',
            time:'2022-04-06 08:47'
            
          },
        ]
      )
      obj.User.bulkCreate(
        [
          {
            account:'admin',
            password:123
          },
          {
            account:'tw',
            password:123
          }
        ]
      )

    })
  } 


module.exports=obj